package com.example.demo_springboot.service;

import com.example.demo_springboot.dao.AccountMapper;
import com.example.demo_springboot.vo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AccoutMyBatisService {
    @Autowired
    private AccountMapper accountMapper;

    public int add(String name, double money) {
        return accountMapper.add(name, money);
    }

    public int addObj(Account acc) {
        return accountMapper.addObj(acc);
    }

    public int update(String name, double money, int id) {
        return accountMapper.update(name, money, id);
    }

    //测试 声明式数据库事务
    @Transactional
    public int updateByXml(String name, double money, int id) throws Exception{
        accountMapper.updateByXml(name, money, id);
        accountMapper.updateByXml(name+"Str1", money+1, 388855);
        int f = 1/0;
        accountMapper.updateByXml(name+"Str2", money+10000, 388855);
        return 1;
    }

    public int delete(int id) {
        return accountMapper.delete(id);
    }
    public Account findAccount(int id) {
        return accountMapper.findAccount(id);
    }
    public List<Account> findAccountList() {
        return accountMapper.findAccountList();
    }

    public Account findByName(String name){
        return accountMapper.findUserByName(name);
    }
}
